package other;

import java.util.Arrays;

public class EightQueensPuzzle {
    private static int max=8;
    private static int[] array = new int[8];
    private static int count=0;
    public static void main(String[] args) {
        check(0);
        System.out.println("总数："+count);
    }

    public  static void check(int n){
        if(n==max){
            print();
            return;
        }

        for(int i=0; i<max; i++){
            array[n] = i;
            if(judge(n)){
                check(n+1);
            }
        }
    }

    public static boolean judge(int n){
        for(int i=0;i<n;i++){
            if(array[i]==array[n]||Math.abs(n-i)==Math.abs(array[n]-array[i])){
                return false;
            }
        }
        return true;
    }

    public static void print(){
        count++;
        System.out.println(Arrays.toString(array));
    }

}
